package com.ruoyi.web.controller.smile;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.smile.domain.McGn;
import com.ruoyi.smile.service.IMcGnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 首页功能列Controller
 *
 * @author xin
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/smile/gn")
public class McGnController extends BaseController {
    @Autowired
    private IMcGnService mcGnService;

    /**
     * 查询首页功能列列表
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:list')")
    @GetMapping("/list")
    public TableDataInfo list(McGn mcGn) {
        startPage();
        List<McGn> list = mcGnService.selectMcGnList(mcGn);
        return getDataTable(list);
    }

    /**
     * 导出首页功能列列表
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:export')")
    @Log(title = "首页功能列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, McGn mcGn) {
        List<McGn> list = mcGnService.selectMcGnList(mcGn);
        ExcelUtil<McGn> util = new ExcelUtil<McGn>(McGn.class);
        util.exportExcel(response, list, "首页功能列数据");
    }

    /**
     * 获取首页功能列详细信息
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mcGnService.selectMcGnById(id));
    }

    /**
     * 新增首页功能列
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:add')")
    @Log(title = "首页功能列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody McGn mcGn) {
        return toAjax(mcGnService.insertMcGn(mcGn));
    }

    /**
     * 修改首页功能列
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:edit')")
    @Log(title = "首页功能列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody McGn mcGn) {
        return toAjax(mcGnService.updateMcGn(mcGn));
    }

    /**
     * 删除首页功能列
     */
    @PreAuthorize("@ss.hasPermi('smile:gn:remove')")
    @Log(title = "首页功能列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mcGnService.deleteMcGnByIds(ids));
    }
}
